from pydub import AudioSegment

def generate_clap_beats(bpm=180, duration_seconds=60, clap_path="clap.mp3"):
    interval_ms = 60000 // bpm
    total_beats = (duration_seconds * 1000) // interval_ms

    # 读取拍手音
    clap = AudioSegment.from_file(clap_path).apply_gain(-2)

    # 如果 clap 太长，就截断
    if len(clap) > interval_ms:
        clap = clap[:interval_ms]
    
    silence = AudioSegment.silent(duration=interval_ms - len(clap))
    beat = clap + silence

    full_track = beat * int(total_beats)
    full_track.export("clap_180bpm.mp3", format="mp3")
    print("✅ 已生成：clap_180bpm.mp3")

generate_clap_beats()
